package com.stwitinc.redmine.res.user;


import com.alibaba.fastjson.JSONObject;
import com.stwitinc.Logger;
import com.stwitinc.redmine.dao.DAO;
import com.stwitinc.servlet.rest.RESTResource;
import com.stwitinc.servlet.rest.ResourceMethod;
import com.stwitinc.servlet.rest.ReturnType;

public class UserRes extends RESTResource
{
	private static final Logger logger = Logger.getLogger(UserRes.class);

	@ResourceMethod(returnType = ReturnType.FORWARD, validateToken = false)
	public String getLogin() throws Exception {
		return "desktop/user/login.jsp";
	}

	@ResourceMethod(returnType = ReturnType.JSON, validateToken = false)
	public JSONObject postLoginState(String userId) throws Exception {
		String password = getParameter("password");
		/*JSONObject loginState = DAO.newUserDAO().login(userId, password, 10);
		return loginState;*/
		JSONObject loginState=new JSONObject();
		loginState.put("responseCode", 0);
		return loginState;
	}

	@ResourceMethod(returnType = ReturnType.REDIRECT, validateToken = false)
	public String getLogout() throws Exception {
		try {
			String tokenId = getToken().getString("tokenId");
			DAO.newUserDAO().logout(tokenId);
		} catch (Exception e) {
			logger.error(e);
		}
		return "welcome";
	}
}
